package com.suray.wcs.service.rescontact;

import com.suray.basic.wcs.plc.pojo.Robot;
import com.suray.basic.wcs.plc.pojo.RobotHeartBaseResult;
import com.suray.wcs.res.msgparse.HeartBaseResult;
import com.suray.wcs.res.msgparse.ResultBase;
import com.suray.wcs.service.pojo.Rgv;
import com.suray.wcs.service.pojo.rgv.rgv.protocol.base.RgvBaseMessage;

import java.util.HashMap;
import java.util.Map;

public class ResultContainer {
    private static final Map<Rgv, ResultContainer> resultContainerMap = new HashMap<>();
    private static final Map<Robot, ResultContainer> robotResultContainerMap = new HashMap<>();
    private final Map<Integer, HeartBaseResult> resultMap = new HashMap<>();
    private final Map<Integer, RobotHeartBaseResult> robotResultMap = new HashMap<>();
    private final Map<Integer, ResultBase> mapResultMap = new HashMap<>();
    private final Map<Integer, RgvBaseMessage> receiveMessaggeMap = new HashMap<>();

    private ResultContainer() {
    }

    public static ResultContainer getContainer(Rgv rgv) {
        if (rgv == null) {
            throw new IllegalArgumentException("小车对象参数为空");
        }
        ResultContainer container = resultContainerMap.get(rgv);
        if (container == null) {
            container = new ResultContainer();
            resultContainerMap.put(rgv, container);
        }
        return container;
    }

    public static ResultContainer getContainer(Robot robot) {
        if (robot == null) {
            throw new IllegalArgumentException("小车对象参数为空");
        }
        ResultContainer container = robotResultContainerMap.get(robot);
        if (container == null) {
            container = new ResultContainer();
            robotResultContainerMap.put(robot, container);
        }
        return container;
    }

    public void putRobotResult(Integer key, RobotHeartBaseResult resResult) {
        if (resResult == null) {
            throw new NullPointerException();
        }
        robotResultMap.put(key, resResult);
    }

    public RobotHeartBaseResult getRobotResult(Integer retCode) {
        return robotResultMap.get(retCode);
    }

    public void putResult(Integer key, HeartBaseResult resResult) {
        if (resResult == null) {
            throw new NullPointerException();
        }
        resultMap.put(key, resResult);
    }

    public HeartBaseResult getResult(Integer retCode) {
        return resultMap.get(retCode);
    }

    public void putMapResultMap(Integer key, ResultBase resResult) {
        if (resResult == null) {
            throw new NullPointerException();
        }
        mapResultMap.put(key, resResult);
    }
    public void putReceiveMessage(Integer key, RgvBaseMessage rgvBaseMessage) {
        if (rgvBaseMessage == null) {
            throw new NullPointerException();
        }

        receiveMessaggeMap.put(key, rgvBaseMessage);
    }

    public RgvBaseMessage getReceiveMessage(Integer retCode) {
        return receiveMessaggeMap.get(retCode);
    }
}
